package com.singer.druid;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.singer.piping.Delete;
import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Properties;

public class SingerDelete implements Delete {
    /**
     * 删除歌手
     */
    @Override
    public void delete( int Id) throws Exception {
        Properties prop = new Properties();
        prop.load(new FileInputStream("src/druid.properties"));

        DataSource data = DruidDataSourceFactory.createDataSource(prop);

        Connection connection = data.getConnection();

        String sql="delete from t_singer where id=?";
         PreparedStatement se= connection.prepareStatement(sql);

         se.setInt(1,Id);

         int count=se.executeUpdate();
         if (count>0){
             System.out.println("删除成功!");
         }
         se.close();
         connection.close();
    }

    @Override
    public void delete1(int Id) throws Exception {
        Properties prop = new Properties();
        prop.load(new FileInputStream("src/druid.properties"));

        DataSource data = DruidDataSourceFactory.createDataSource(prop);

        Connection connection = data.getConnection();

        String sql="delete from t_judge where id=?";
        PreparedStatement set= connection.prepareStatement(sql);

        set.setInt(1,Id);

        int count=set.executeUpdate();
        if (count>0){
            System.out.println("删除成功!");
        }
        set.close();
        connection.close();
    }
}
